package com.allwees.support.payment.paypal.configuration;

import com.paypal.core.PayPalEnvironment;
import com.allwees.support.payment.paypal.constant.EPaypalMode;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;


@Data
@Configuration
@ConfigurationProperties(prefix = "payment.paypal")
public class PaypalProperties {

    private String mode;
    private String account;
    private String clientId;
    private String secret;
    private String returnURL;
    private String cancelURL;
    private String redirectURL1;
    private String redirectURL2;
    private String redirectURL3;

    static PayPalEnvironment environment = null;

    @PostConstruct
    public void run() {
        if (EPaypalMode.LIVE.name().equals(mode.toUpperCase())) {
            environment = new PayPalEnvironment.Live(clientId, secret);
        } else {
            environment = new PayPalEnvironment.Sandbox(clientId, secret);
        }
    }

    public static PayPalEnvironment getEnvironment() {
        return environment;
    }
}
